﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using RTW.Models;
using RTW.Servers;
using RTW.Web.Comm;

namespace RTW.Web.Areas.System.Controllers
{
    [Area("System")]
    public class BaseDataController : CommController
    {
        TBaseDataServer baseDataServer;
        public BaseDataController()
        {
            baseDataServer = new TBaseDataServer();
        }

        public IActionResult BaseDataManagement()
        {
            return View();
        }

        public async Task<IActionResult> BaseDataEdit(string ID)
        {
            TBaseData baseData = new TBaseData();
            //编辑或新增
            if (string.IsNullOrEmpty(ID))
            {

            }
            else
            {
                //修改时回绑字段
                baseData = await baseDataServer.GetByOneAsync(m => m.ID == ID);
                ViewBag.DMID = baseData.DMID;
            }
            return View(baseData);
        }
        public async Task<IActionResult> BaseDataMainEdit(string ID)
        {
            TBaseData baseData = new TBaseData();
            //编辑或新增
            if (string.IsNullOrEmpty(ID))
            {

            }
            else
            {
                //修改时回绑字段
                baseData = await baseDataServer.GetByOneAsync(m => m.ID == ID);
                ViewBag.DMID = baseData.DMID;
            }
            return View(baseData);
        }



        public async Task<IActionResult> GetMainData()
        {
            var ulist = await baseDataServer.GetAsync(m=>m.Type=="");
            return Json(ulist);
        }

        public async Task<IActionResult> GetSubData(string Type)
        {
            var ulist = await baseDataServer.GetAsync(m => m.Type == Type);
            return Json(ulist);
        }
    }
}
